﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Web;
using System.Xml;
using System.Configuration;

namespace Tickz
{
    /// <summary>
    /// 配置BS整个应用的参数
    /// </summary>
    public class BSConfigParams : ConfigParams
    {
        //得到真实路径
        private string applicationRootRealPath = HttpContext.Current.Request.PhysicalApplicationPath.Substring(0, HttpContext.Current.Request.PhysicalApplicationPath.Length - 1).ToString();
        //是否写日志
        public static bool islog = false;

        public override string ApplicationRootRealPath
        {
            get { return applicationRootRealPath; }
            set { applicationRootRealPath = value; }
        }

        //得到虚拟路径的跟路径
        private string applicationRootVirtualPath =((HttpContext.Current.Request.ApplicationPath == "/") ? "" : HttpContext.Current.Request.ApplicationPath);
        public override string ApplicationRootVirtualPath
        {
            get { return applicationRootVirtualPath; }
            set { applicationRootVirtualPath = value; }
        }
        public BSConfigParams() { 
        
        }
        //根据key取得配置的值
        public override string GetTickzConfig(string key)
        {
            XmlDocument document = new XmlDocument();
            document.Load(HttpContext.Current.Server.MapPath(@"~/tickz.Config"));
            XmlElement xmlEle = document.GetElementById(key);
            //判断是否存在该节点
            if (xmlEle == null)
            {
                return null;
            }
            return document.GetElementById(key).Attributes["value"].Value;
        }

        //设置存在的key的值
        public override void SetTickzConfig(string key, string value)
        {
            XmlDocument document = new XmlDocument();
            document.Load(HttpContext.Current.Server.MapPath(@"~/tickz.Config"));
            XmlElement xmlEle = document.GetElementById(key);
            //判断是否存在该节点
            if (xmlEle != null)
            {
                document.GetElementById(key).Attributes["value"].Value = value;
                document.Save(HttpContext.Current.Server.MapPath(@"~/tickz.Config"));
            }   
        }
        public static string baseDomain = "888.cn";


    }
}


